home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_136 / bison / calc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  22KB  |  773 lines

  1.  
  2. /*  A Bison parser, made from calc.y  */
  3.  
  4. #define    DIGIT    258
  5. #define    LETTER    259
  6. #define    EXIT    260
  7. #define    UMINUS    261
  8.  
  9. #line 1 "calc.y"
  10.  
  11. #include <ctype.h>
  12.  
  13. int regs[26];
  14. int base;
  15.  
  16. int val;
  17. int printflag;
  18.  
  19.  
  20. #ifndef YYLTYPE
  21. typedef
  22.   struct yyltype
  23. {
  24.       int timestamp;
  25.       int first_line;
  26.       int first_column;
  27. int last_line;
  28.       int last_column;
  29.       char *text;
  30.    }
  31. yyltype;
  32.  
  33. #define YYLTYPE yyltype
  34. #endif
  35.  
  36. #define    YYACCEPT    return(0)
  37. #define    YYABORT    return(1)
  38. #define    YYERROR    return(1)
  39. #ifndef YYSTYPE
  40. #define YYSTYPE int
  41. #endif
  42. #include <stdio.h>
  43.  
  44. #ifndef __STDC__
  45. #define const
  46. #endif
  47.  
  48.  
  49.  
  50. #define    YYFINAL        31
  51. #define    YYFLAG        -32768
  52. #define    YYNTBASE    17
  53.  
  54. #define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 20)
  55.  
  56. static const char yytranslate[] = {     0,
  57.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  58.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  59.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  60.      2,     2,     2,     2,     2,     2,    12,     7,     2,    15,
  61.     16,    10,     8,     2,     9,     2,    11,     2,     2,     2,
  62.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  63.     14,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  64.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  65.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  66.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  67.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  68.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  69.      2,     2,     2,     6,     2,     2,     2,     2,     2,     2,
  70.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  71.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  72.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  73.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  74.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  75.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  76.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  77.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  78.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  79.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  80.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  81.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  82.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  83.     13
  84. };
  85.  
  86. static const short yyrline[] = {     0,
  87.     24,    26,    28,    32,    34,    42,    44,    46,    48,    50,
  88.     52,    54,    56,    58,    63,    65
  89. };
  90.  
  91. static const char * yytname[] = {     0,
  92. "error","$illegal.","DIGIT","LETTER","EXIT","'|'","'&'","'+'","'-'","'*'",
  93. "'/'","'%'","UMINUS","'='","'('","')'","stmt"
  94. };
  95.  
  96. static const short yyr1[] = {     0,
  97.     17,    17,    17,    18,    18,    18,    18,    18,    18,    18,
  98.     18,    18,    18,    18,    19,    19
  99. };
  100.  
  101. static const short yyr2[] = {     0,
  102.      1,     3,     1,     3,     3,     3,     3,     3,     3,     3,
  103.      3,     2,     1,     1,     1,     2
  104. };
  105.  
  106. static const short yydefact[] = {     0,
  107.     15,    13,     3,     0,     0,     1,    14,     0,    13,    12,
  108.      0,     0,     0,     0,     0,     0,     0,     0,    16,     2,
  109.      4,    10,    11,     5,     6,     7,     8,     9,     0,     0,
  110.      0
  111. };
  112.  
  113. static const short yydefgoto[] = {    29,
  114.      6,     7
  115. };
  116.  
  117. static const short yypact[] = {    12,
  118. -32768,   -12,-32768,    15,    15,    36,     0,    15,-32768,-32768,
  119.     25,    15,    15,    15,    15,    15,    15,    15,-32768,    36,
  120. -32768,    42,    47,    -5,    -5,-32768,-32768,-32768,    20,    22,
  121. -32768
  122. };
  123.  
  124. static const short yypgoto[] = {-32768,
  125.     -4,-32768
  126. };
  127.  
  128.  
  129. #define    YYLAST        59
  130.  
  131.  
  132. static const short yytable[] = {    10,
  133.     11,     8,    19,    20,    16,    17,    18,    22,    23,    24,
  134.     25,    26,    27,    28,     1,     2,     3,     1,     9,    30,
  135.      4,    31,     0,     4,     0,     0,     5,     0,     0,     5,
  136.     12,    13,    14,    15,    16,    17,    18,     0,     0,     0,
  137.     21,    12,    13,    14,    15,    16,    17,    18,    13,    14,
  138.     15,    16,    17,    18,    14,    15,    16,    17,    18
  139. };
  140.  
  141. static const short yycheck[] = {     4,
  142.      5,    14,     3,     8,    10,    11,    12,    12,    13,    14,
  143.     15,    16,    17,    18,     3,     4,     5,     3,     4,     0,
  144.      9,     0,    -1,     9,    -1,    -1,    15,    -1,    -1,    15,
  145.      6,     7,     8,     9,    10,    11,    12,    -1,    -1,    -1,
  146.     16,     6,     7,     8,     9,    10,    11,    12,     7,     8,
  147.      9,    10,    11,    12,     8,     9,    10,    11,    12
  148. };
  149. #define YYPURE 1
  150.  
  151. #line 2 "bison.simple"
  152.  
  153. /* Skeleton output parser for bison,
  154.    copyright (C) 1984 Bob Corbett and Richard Stallman
  155.  
  156.                NO WARRANTY
  157.  
  158.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  159. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  160. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  161. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  162. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  163. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  164. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  165. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  166. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  167. CORRECTION.
  168.  
  169.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  170. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  171. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  172. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  173. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  174. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  175. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  176. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  177. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  178. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  179.  
  180.         GENERAL PUBLIC LICENSE TO COPY
  181.  
  182.   1. You may copy and distribute verbatim copies of this source file
  183. as you receive it, in any medium, provided that you conspicuously and
  184. appropriately publish on each copy a valid copyright notice "Copyright
  185. (C) 1985 Free Software Foundation, Inc."; and include following the
  186. copyright notice a verbatim copy of the above disclaimer of warranty
  187. and of this License.  You may charge a distribution fee for the
  188. physical act of transferring a copy.
  189.  
  190.   2. You may modify your copy or copies of this source file or
  191. any portion of it, and copy and distribute such modifications under
  192. the terms of Paragraph 1 above, provided that you also do the following:
  193.  
  194.     a) cause the modified files to carry prominent notices stating
  195.     that you changed the files and the date of any change; and
  196.  
  197.     b) cause the whole of any work that you distribute or publish,
  198.     that in whole or in part contains or is a derivative of this
  199.     program or any part thereof, to be licensed at no charge to all
  200.     third parties on terms identical to those contained in this
  201.     License Agreement (except that you may choose to grant more
  202.     extensive warranty protection to third parties, at your option).
  203.  
  204.     c) You may charge a distribution fee for the physical act of
  205.     transferring a copy, and you may at your option offer warranty
  206.     protection in exchange for a fee.
  207.  
  208.   3. You may copy and distribute this program or any portion of it in
  209. compiled, executable or object code form under the terms of Paragraphs
  210. 1 and 2 above provided that you do the following:
  211.  
  212.     a) cause each such copy to be accompanied by the
  213.     corresponding machine-readable source code, which must
  214.     be distributed under the terms of Paragraphs 1 and 2 above; or,
  215.  
  216.     b) cause each such copy to be accompanied by a
  217.     written offer, with no time limit, to give any third party
  218.     free (except for a nominal shipping charge) a machine readable
  219.     copy of the corresponding source code, to be distributed
  220.     under the terms of Paragraphs 1 and 2 above; or,
  221.  
  222.     c) in the case of a recipient of this program in compiled, executable
  223.     or object code form (without the corresponding source code) you
  224.     shall cause copies you distribute to be accompanied by a copy
  225.     of the written offer of source code which you received along
  226.     with the copy you received.
  227.  
  228.   4. You may not copy, sublicense, distribute or transfer this program
  229. except as expressly provided under this License Agreement.  Any attempt
  230. otherwise to copy, sublicense, distribute or transfer this program is void and
  231. your rights to use the program under this License agreement shall be
  232. automatically terminated.  However, parties who have received computer
  233. software programs from you with this License Agreement will not have
  234. their licenses terminated so long as such parties remain in full compliance.
  235.  
  236.   5. If you wish to incorporate parts of this program into other free
  237. programs whose distribution conditions are different, write to the Free
  238. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  239. worked out a simple rule that can be stated here, but we will often permit
  240. this.  We will be guided by the two goals of preserving the free status of
  241. all derivatives of our free software and of promoting the sharing and reuse of
  242. software.
  243.  
  244.  
  245. In other words, you are welcome to use, share and improve this program.
  246. You are forbidden to forbid anyone else to use, share and improve
  247. what you give them.   Help stamp out software-hoarding!  */
  248.  
  249. /* This is the parser code that is written into each bison parser
  250.   when the %semantic_parser declaration is not specified in the grammar.
  251.   It was written by Richard Stallman by simplifying the hairy parser
  252.   used when %semantic_parser is specified.  */
  253.  
  254. /* Note: there must be only one dollar sign in this file.
  255.    It is replaced by the list of actions, each action
  256.    as one case of the switch.  */
  257.  
  258. #define yyerrok        (yyerrstatus = 0)
  259. #define yyclearin    (yychar = YYEMPTY)
  260. #define YYEMPTY        -2
  261. #define YYEOF        0
  262. #define YYFAIL        goto yyerrlab;
  263.  
  264. #define YYTERROR    1
  265.  
  266. #ifndef YYIMPURE
  267. #define YYLEX        yylex()
  268. #endif
  269.  
  270. #ifndef YYPURE
  271. #define YYLEX        yylex(&yylval, &yylloc)
  272. #endif
  273.  
  274. /* If nonreentrant, generate the variables here */
  275.  
  276. #ifndef YYIMPURE
  277.  
  278. int    yychar;            /*  the lookahead symbol        */
  279. YYSTYPE    yylval;            /*  the semantic value of the        */
  280.                 /*  lookahead symbol            */
  281.  
  282. YYLTYPE yylloc;            /*  location data for the lookahead    */
  283.                 /*  symbol                */
  284.  
  285. int yydebug = 0;        /*  nonzero means print parse trace    */
  286.  
  287. #endif  /* YYIMPURE */
  288.  
  289.  
  290. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  291.  
  292. #ifndef    YYMAXDEPTH
  293. #define YYMAXDEPTH 200
  294. #endif
  295.  
  296. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  297.     (effective only if the built-in stack extension method is used).  */
  298.  
  299. #ifndef YYMAXLIMIT
  300. #define YYMAXLIMIT 10000
  301. #endif
  302.  
  303.  
  304. #line 87 "bison.simple"
  305. int
  306. yyparse()
  307. {
  308.   register int yystate;
  309.   register int yyn;
  310.   register short *yyssp;
  311.   register YYSTYPE *yyvsp;
  312.   YYLTYPE *yylsp;
  313.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  314.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  315.  
  316.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  317.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  318.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  319.  
  320.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  321.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  322.   YYLTYPE *yyls = yylsa;
  323.  
  324.   int yymaxdepth = YYMAXDEPTH;
  325.  
  326. #ifndef YYPURE
  327.  
  328.   int yychar;
  329.   YYSTYPE yylval;
  330.   YYLTYPE yylloc;
  331.  
  332.   extern int yydebug;
  333.  
  334. #endif
  335.  
  336.  
  337.   YYSTYPE yyval;        /*  the variable used to return        */
  338.                 /*  semantic values from the action    */
  339.                 /*  routines                */
  340.  
  341.   int yylen;
  342.  
  343.   if (yydebug)
  344.     fprintf(stderr, "Starting parse\n");
  345.  
  346.   yystate = 0;
  347.   yyerrstatus = 0;
  348.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  349.  
  350.   /* Initialize stack pointers.
  351.      Waste one element of value and location stack
  352.      so that they stay on the same level as the state stack.  */
  353.  
  354.   yyssp = yyss - 1;
  355.   yyvsp = yyvs;
  356.   yylsp = yyls;
  357.  
  358. /* Push a new state, which is found in  yystate  .  */
  359. /* In all cases, when you get here, the value and location stacks
  360.    have just been pushed. so pushing a state here evens the stacks.  */
  361. yynewstate:
  362.  
  363.   *++yyssp = yystate;
  364.  
  365.   if (yyssp >= yyss + yymaxdepth - 1)
  366.     {
  367.       /* Give user a chance to reallocate the stack */
  368.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  369.       YYSTYPE *yyvs1 = yyvs;
  370.       YYLTYPE *yyls1 = yyls;
  371.       short *yyss1 = yyss;
  372.  
  373.       /* Get the current used size of the three stacks, in elements.  */
  374.       int size = yyssp - yyss + 1;
  375.  
  376. #ifdef yyoverflow
  377.       /* Each stack pointer address is followed by the size of
  378.      the data in use in that stack, in bytes.  */
  379.       yyoverflow("parser stack overflow",
  380.          &yyss1, size * sizeof (*yyssp),
  381.          &yyvs1, size * sizeof (*yyvsp),
  382.          &yyls1, size * sizeof (*yylsp),
  383.          &yymaxdepth);
  384.  
  385.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  386. #else /* no yyoverflow */
  387.       /* Extend the stack our own way.  */
  388.       if (yymaxdepth >= YYMAXLIMIT)
  389.     yyerror("parser stack overflow");
  390.       yymaxdepth *= 2;
  391.       if (yymaxdepth > YYMAXLIMIT)
  392.     yymaxdepth = YYMAXLIMIT;
  393.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  394.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  395.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  396.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  397.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  398.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  399. #endif /* no yyoverflow */
  400.  
  401.       yyssp = yyss + size - 1;
  402.       yylsp = yyls + size - 1;
  403.       yyvsp = yyvs + size - 1;
  404.  
  405.       if (yydebug)
  406.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  407.  
  408.       if (yyssp >= yyss + yymaxdepth - 1)
  409.     YYERROR;
  410.     }
  411.  
  412.   if (yydebug)
  413.     fprintf(stderr, "Entering state %d\n", yystate);
  414.  
  415. /* Do appropriate processing given the current state.  */
  416. /* Read a lookahead token if we need one and don't already have one.  */
  417. yyresume:
  418.  
  419.   /* First try to decide what to do without reference to lookahead token.  */
  420.  
  421.   yyn = yypact[yystate];
  422.   if (yyn == YYFLAG)
  423.     goto yydefault;
  424.  
  425.   /* Not known => get a lookahead token if don't already have one.  */
  426.  
  427.   /* yychar is either YYEMPTY or YYEOF
  428.      or a valid token in external form.  */
  429.  
  430.   if (yychar == YYEMPTY)
  431.     {
  432.       yychar = YYLEX;
  433.     }
  434.  
  435.   /* Convert token to internal form (in yychar1) for indexing tables with */
  436.  
  437.   if (yychar <= 0)        /* This means end of input. */
  438.     {
  439.       yychar1 = 0;
  440.       yychar = YYEOF;        /* Don't call YYLEX any more */
  441.  
  442.       if (yydebug)
  443.     fprintf(stderr, "Now at end of input.\n");
  444.     }
  445.   else
  446.     {
  447.       yychar1 = YYTRANSLATE(yychar);
  448.  
  449.       if (yydebug)
  450.     fprintf(stderr, "Parsing next token; it is %d (%s)\n", yychar, yytname[yychar1]);
  451.     }
  452.  
  453.   yyn += yychar1;
  454.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  455.     goto yydefault;
  456.  
  457.   yyn = yytable[yyn];
  458.  
  459.   /* yyn is what to do for this token type in this state.
  460.      Negative => reduce, -yyn is rule number.
  461.      Positive => shift, yyn is new state.
  462.        New state is final state => don't bother to shift,
  463.        just return success.
  464.      0, or most negative number => error.  */
  465.  
  466.   if (yyn < 0)
  467.     {
  468.       if (yyn == YYFLAG)
  469.     goto yyerrlab;
  470.       yyn = -yyn;
  471.       goto yyreduce;
  472.     }
  473.   else if (yyn == 0)
  474.     goto yyerrlab;
  475.  
  476.   if (yyn == YYFINAL)
  477.     YYACCEPT;
  478.  
  479.   /* Shift the lookahead token.  */
  480.  
  481.   if (yydebug)
  482.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  483.  
  484.   /* Discard the token being shifted unless it is eof.  */
  485.   if (yychar != YYEOF)
  486.     yychar = YYEMPTY;
  487.  
  488.   *++yyvsp = yylval;
  489.   *++yylsp = yylloc;
  490.  
  491.   /* count tokens shifted since error; after three, turn off error status.  */
  492.   if (yyerrstatus) yyerrstatus--;
  493.  
  494.   yystate = yyn;
  495.   goto yynewstate;
  496.  
  497. /* Do the default action for the current state.  */
  498. yydefault:
  499.  
  500.   yyn = yydefact[yystate];
  501.   if (yyn == 0)
  502.     goto yyerrlab;
  503.  
  504. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  505. yyreduce:
  506.   yylen = yyr2[yyn];
  507.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  508.  
  509.   if (yydebug)
  510.     {
  511.       if (yylen == 1)
  512.     fprintf (stderr, "Reducing 1 value via line %d, ",
  513.          yyrline[yyn]);
  514.       else
  515.     fprintf (stderr, "Reducing %d values via line %d, ",
  516.          yylen, yyrline[yyn]);
  517.     }
  518.  
  519.  
  520.   switch (yyn) {
  521.  
  522. case 1:
  523. #line 25 "calc.y"
  524. { val = yyvsp[0]; printflag = 1; ;
  525.     break;}
  526. case 2:
  527. #line 27 "calc.y"
  528. { regs[yyvsp[-2]] = yyvsp[0]; ;
  529.     break;}
  530. case 3:
  531. #line 29 "calc.y"
  532. { exit(0); ;
  533.     break;}
  534. case 4:
  535. #line 33 "calc.y"
  536. { yyval = yyvsp[-1]; ;
  537.     break;}
  538. case 5:
  539. #line 35 "calc.y"
  540. { if (yyvsp[-2] == 69)
  541.                 {
  542.                   yyval = 2;
  543.                   printf ("$1 became %d\n", yyvsp[-2]);
  544.                   yyvsp[-2] = 69;
  545.                 }
  546.               yyval = yyvsp[-2] + yyvsp[0]; ;
  547.     break;}
  548. case 6:
  549. #line 43 "calc.y"
  550. { yyval = yyvsp[-2] - yyvsp[0]; ;
  551.     break;}
  552. case 7:
  553. #line 45 "calc.y"
  554. { yyval = yyvsp[-2] * yyvsp[0]; ;
  555.     break;}
  556. case 8:
  557. #line 47 "calc.y"
  558. { yyval = yyvsp[-2] / yyvsp[0]; ;
  559.     break;}
  560. case 9:
  561. #line 49 "calc.y"
  562. { yyval = yyvsp[-2] % yyvsp[0]; ;
  563.     break;}
  564. case 10:
  565. #line 51 "calc.y"
  566. { yyval = yyvsp[-2] | yyvsp[0]; ;
  567.     break;}
  568. case 11:
  569. #line 53 "calc.y"
  570. { yyval = yyvsp[-2] & yyvsp[0]; ;
  571.     break;}
  572. case 12:
  573. #line 55 "calc.y"
  574. { yyval = - yyvsp[0]; ;
  575.     break;}
  576. case 13:
  577. #line 57 "calc.y"
  578. { yyval = regs[yyvsp[0]]; ;
  579.     break;}
  580. case 15:
  581. #line 64 "calc.y"
  582. { yyval = yyvsp[0];  base = (yyvsp[0] == 0) ? 8 : 10; ;
  583.     break;}
  584. case 16:
  585. #line 66 "calc.y"
  586. { yyval = base * yyvsp[-1] + yyvsp[0]; ;
  587.     break;}
  588. }
  589.    /* the action file gets copied in in place of this dollarsign */
  590. #line 303 "bison.simple"
  591.  
  592.   yyvsp -= yylen;
  593.   yylsp -= yylen;
  594.   yyssp -= yylen;
  595.  
  596.   if (yydebug)
  597.     {
  598.       short *ssp1 = yyss - 1;
  599.       fprintf (stderr, "state stack now", yyssp-yyss);
  600.       while (ssp1 != yyssp)
  601.     fprintf (stderr, " %d", *++ssp1);
  602.       fprintf (stderr, "\n");
  603.     }
  604.  
  605.   *++yyvsp = yyval;
  606.  
  607.   yylsp++;
  608.   if (yylen == 0)
  609.     {
  610.       yylsp->first_line = yylloc.first_line;
  611.       yylsp->first_column = yylloc.first_column;
  612.       yylsp->last_line = (yylsp-1)->last_line;
  613.       yylsp->last_column = (yylsp-1)->last_column;
  614.       yylsp->text = 0;
  615.     }
  616.   else
  617.     {
  618.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  619.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  620.     }
  621.  
  622.   /* Now "shift" the result of the reduction.
  623.      Determine what state that goes to,
  624.      based on the state we popped back to
  625.      and the rule number reduced by.  */
  626.  
  627.   yyn = yyr1[yyn];
  628.  
  629.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  630.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  631.     yystate = yytable[yystate];
  632.   else
  633.     yystate = yydefgoto[yyn - YYNTBASE];
  634.  
  635.   goto yynewstate;
  636.  
  637. yyerrlab:   /* here on detecting error */
  638.  
  639.   if (! yyerrstatus)
  640.     /* If not already recovering from an error, report this error.  */
  641.     {
  642.       yyerror("parse error");
  643.     }
  644.  
  645.   if (yyerrstatus == 3)
  646.     {
  647.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  648.  
  649.       /* return failure if at end of input */
  650.       if (yychar == YYEOF)
  651.     YYERROR;
  652.  
  653.       if (yydebug)
  654.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  655.  
  656.       yychar = YYEMPTY;
  657.     }
  658.  
  659.   /* Else will try to reuse lookahead token
  660.      after shifting the error token.  */
  661.  
  662.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  663.  
  664.   goto yyerrhandle;
  665.  
  666. yyerrdefault:  /* current state does not do anything special for the error token. */
  667.  
  668. #if 0
  669.   /* This is wrong; only states that explicitly want error tokens
  670.      should shift them.  */
  671.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  672.   if (yyn) goto yydefault;
  673. #endif
  674.  
  675. yyerrpop:   /* pop the current state because it cannot handle the error token */
  676.  
  677.   if (yyssp == yyss) YYERROR;
  678.   yyvsp--;
  679.   yylsp--;
  680.   yystate = *--yyssp;
  681.  
  682.   if (yydebug)
  683.     {
  684.       short *ssp1 = yyss - 1;
  685.       fprintf (stderr, "Error: state stack now", yyssp-yyss);
  686.       while (ssp1 != yyssp)
  687.     fprintf (stderr, " %d", *++ssp1);
  688.       fprintf (stderr, "\n");
  689.     }
  690.  
  691. yyerrhandle:
  692.  
  693.   yyn = yypact[yystate];
  694.   if (yyn == YYFLAG)
  695.     goto yyerrdefault;
  696.  
  697.   yyn += YYTERROR;
  698.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  699.     goto yyerrdefault;
  700.  
  701.   yyn = yytable[yyn];
  702.   if (yyn < 0)
  703.     {
  704.       if (yyn == YYFLAG)
  705.     goto yyerrpop;
  706.       yyn = -yyn;
  707.       goto yyreduce;
  708.     }
  709.   else if (yyn == 0)
  710.     goto yyerrpop;
  711.  
  712.   if (yyn == YYFINAL)
  713.     YYACCEPT;
  714.  
  715.   if (yydebug)
  716.     fprintf(stderr, "Shifting error token, ");
  717.  
  718.   *++yyvsp = yylval;
  719.   *++yylsp = yylloc;
  720.  
  721.   yystate = yyn;
  722.   goto yynewstate;
  723. }
  724. #line 69 "calc.y"
  725.  
  726.  
  727. static int eol;
  728.  
  729. int
  730. yylex()
  731. {
  732.   int c;
  733.  
  734.   while ( (c=getchar()) == ' ') {}
  735.   if (c == '\n')
  736.     { eol = 1;
  737.       return 0; }
  738.   if (c == 'Q')
  739.     return(EXIT);
  740.   if (islower(c))
  741.     {
  742.       yylval = c - 'a';
  743.       return (LETTER);
  744.     }
  745.   if (isdigit(c))
  746.     {
  747.       yylval = c - '0';
  748.       return (DIGIT);
  749.     }
  750.   return (c);
  751. }
  752.  
  753. yyerror(s)
  754. char *s;
  755. {
  756.   printf("%s\n", s);
  757. }
  758.  
  759. main()
  760. {
  761.   for (;;)
  762.     {
  763.       eol = 0;
  764.       printflag = 0;
  765.  
  766.       if (yyparse()) printflag = 0;
  767.  
  768.       if (printflag) printf("%d\n", val);
  769.  
  770.       while (!eol) yylex();
  771.     }
  772. }
  773.